import CryptoJS from 'crypto-js';
const KEY = 'code2023030108145310241024' // 秘钥
const iv = '10241024'


export const AES_Encrypt = (plaintext) => {
  const ciphertext = CryptoJS.TripleDES.encrypt(plaintext, CryptoJS.enc.Utf8.parse(KEY), {
    iv: CryptoJS.enc.Utf8.parse(iv),
    mode: CryptoJS.mode.CBC, // CBC模式是Triple DES的推荐模式
    padding: CryptoJS.pad.Pkcs7
  });
  return ciphertext.toString();
}


/**
 * AES 解密
 */
export const AES_Decrypt = (encryptedText) => {
  const bytes = CryptoJS.TripleDES.decrypt(encryptedText, CryptoJS.enc.Utf8.parse(KEY), {
    iv: CryptoJS.enc.Utf8.parse(iv),
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });
  return bytes.toString(CryptoJS.enc.Utf8);
}